package collections;

import java.util.HashMap;
import java.util.HashSet;

public class HashMapTest1 {

    public static void main(String[] args) {
        test1();
//        test2();
    }


    public static void test1() {
        HashMap<Object, Object> map = new HashMap<>();
        MyClass m1 = new MyClass("myClass 1", 5);
        MyClass m2 = new MyClass("myClass 2", 6);
        MyClass m3 = new MyClass("myClass 3", 9);
        MyClass m4 = new MyClass("myClass 4", 9);
        MyClass m5 = new MyClass("myClass 5", 9);
        map.put(m3, m1);
        map.put(m4, m2);
        map.put(m5, m5);
        System.out.println(map);
        System.out.println("1" + new String("2") == "12");
    }

    public static void test2() {


    }

    private static class HashMapTest1_MySet1<E> extends HashSet<E> {
        @Override
        public int hashCode() {
            System.out.println("HashMapTest1_MySet1 -> hashcode");
            return super.hashCode();
        }

        @Override
        public boolean equals(Object o) {
            System.out.println("HashMapTest1_MySet1 -> equals");
            return super.equals(o);
        }
    }

    private static class MyClass {

        String name;
        int h;

        MyClass(String s, int h) {
            name = s;
            this.h = h;
        }

        @Override
        public int hashCode() {
            System.out.println("MyClass -> hashcode");
            return h;
        }

        @Override
        public boolean equals(Object o) {
            System.out.println("MyClass- > equals");
            return super.equals(o);
        }

        @Override
        public String toString() {
            return "MyClass{" +
                    "name='" + name + '\'' +
                    ", h=" + h +
                    '}';
        }
    }
}
